/**
 * This class extends the TextView class. It create an always focused text view object.
 * It can be used instead of a TextView when we need that its inner text is (auto)scrollable. 
 */

package com.android.vocalNotes;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;

public class ScrollingTextView extends TextView {

   /**
    * Constructor.
    * 
    * @param context
    *           The application environment
    */
   public ScrollingTextView(Context context) {
      super(context);
   }

   /**
    * Constructor.
    * 
    * @param context
    *           The application environment
    * @param attrs
    *           The attributes of the XML tag that is inflating the view
    */
   public ScrollingTextView(Context context, AttributeSet attrs) {
      super(context, attrs);
   }

   /**
    * Constructor.
    * 
    * @param context
    *           The application environment
    * @param attrs
    *           The attributes of the XML tag that is inflating the view
    * @param defStyle
    *           The default style to apply to this view
    */
   public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);
   }

   /**
    * This method is called by the view system when the focus state of this view
    * changes.
    * 
    * @param focused
    *           True if the View has focus; false otherwise.
    * @param direction
    *           The direction focus has moved when requestFocus() is called to
    *           give this view focus. Values are FOCUS_UP, FOCUS_DOWN,
    *           FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, or FOCUS_BACKWARD. It
    *           may not always apply, in which case use the default.
    * @param previouslyFocusedRect
    *           The rectangle, in this view's coordinate system, of the
    *           previously focused view. If applicable, this will be passed in
    *           as finer grained information about where the focus is coming
    *           from (in addition to direction). Will be null otherwise.
    */
   @Override
   protected void onFocusChanged(boolean focused, int direction,
         Rect previouslyFocusedRect) {
      if (focused) {
         super.onFocusChanged(focused, direction, previouslyFocusedRect);
      }
   }

   /**
    * This method is Called when the window containing this view gains or loses
    * focus.
    * 
    * @param focused
    *           True if the window containing this view now has focus, false
    *           otherwise.
    */
   @Override
   public void onWindowFocusChanged(boolean focused) {
      if (focused) {
         super.onWindowFocusChanged(focused);
      }
   }

   /**
    * This method makes the view to be always focused. This is necessary to make
    * its inner text auto-scrolling.
    * 
    * @return true always
    */
   @Override
   public boolean isFocused() {
      return true;
   }
}